Tiny Hexer Script: Functions
This page shows all available Tiny Hexer Script functions. Note: As
of version 1.6.0.2 of Tiny Hexer most functions can be used like commands, i. e. functions which have no equally
named command counterpart can be used as first keyword in a script line (in
this case the function's result is discarded).
more...
less...
ABS() returns the absolute value of the argument number
Sample:
VAR float DOUBLE integer SIGWORD
float = ABS(-2.5):= returns 2.5
integer = ABS(-4711):= returns 4711
MSGBOX (TEXT(float)+', '+DEC(integer))
more...
less...
ARCCOS() returns the arcus cosine of the argument number (range -1..1). The result is in the range
0..PI.
more...
less...
ARCSIN() returns the arcus sine of the argument number (range -1..1). The result is in the range
-PI//2..PI//2.
more...
less...
ARCTAN() returns the arcus tangent of the argument number. The result is in the range -PI//2..PI//2.
TEXT
ASKDIRECTORY([
title [,
selection]])
*
more...
less...
Use the ASKDIRECTORY() function to let the user select a
directory from a dialog.
The optional title parameter sets the
title of the directory selection dialog.
The optional selection parameter tells
Tiny Hexer which directory should be selected when the dialog is shown
(on some versions of Windows this will not work).
Note: If the user chooses the "Cancel" button in the directory
selection dialog, the script will be terminated if no error handler is
set.
Sample:
= select a directory and display it in a message box
VAR dir TEXT
LET dir = ASKDIRECTORY('Please choose a directory', 'c:\')
MSGBOX ('You selected the directory '+dir)
BYTE
ASKFINDOPTIONS(
caption,
searchdata_ref,
istext_ref,
ignorecase_ref,
wildcard_ref)
*
Parameters:
caption: a
TEXT expression
searchdata_ref,
istext_ref,
ignorecase_ref,
wildcard_ref: expressions of type
VARREF
more...
less...
Use the
ASKFINDOPTIONS() function to let the user choose search
options in a find dialog.
If the User clicks the Cancel button, the function returns
0,
otherwise
1 is returned and the find options are stored in the
variables referenced by the *_ref expressions:
searchdata_ref must refer to a
TEXT variable that will be set to the text to search
for.
istext_ref must refer to a
BYTE variable set
to the value of the "Find Text" and "Regular Expression" checkboxes
(
2 if "Regular Expression" is checked,
1 if "Find Text"
is checked,
0 otherwise).
ignorecase_ref must refer to a
BYTE variable set to the value of the "Ignore Case"
checkbox.
wildcard_ref must refer to a
TEXT variable
that is set to the wildcard text if the user checked the "Wildcard"
checkbox, otherwise, it's set to an empty string.
Sample:
= search for all occurences of a string in the current file, store
= the results in the position list and save the positions list to disk
= query find options
var f_Text TEXT, f_FindText BYTE, f_IgnoreCase BYTE, f_Wildcard TEXT
if (not AskFindOptions("Search the whole file and save results", @f_Text, @f_FindText, @f_IgnoreCase, @f_Wildcard))
end
endif
= query file name for list saving
var res_file TEXT
res_file = AskSaveFileName("Choose name of search results file", 'Text Files (*.txt)|*.txt')
= clear current contents of the position list
if (POSITION_COUNT)
!CMD.PosList.PosListSelectAll
!CMD.PosList.PosListDeleteSelected
endif
= find all and store in the position list
!CMD.EditFindStore f_text, f_ignorecase, f_findtext, f_wildcard
if (not POSITION_COUNT)
= not found
error "Data not found!"
else
= save
POSITION_DESC = ("Search results for: "+f_text+" on "+CURRENTFILE)
!CMD.PosList.PosListSave res_file
endif
TEXT
ASKOPENFILENAME([
caption
[,
filter [,
default ]]])
*
more...
less...
Use the ASKOPENFILENAME() function to let the user select a
filename for file loading.
The optional caption parameter sets
the title of the file selection dialog.
The optional filter parameter tells
Tiny Hexer what file types to display in the file selection dialog.
This parameter is a TEXT string in the form of "Description|File
mask[|...]" (e.g. "Text files|*.txt|All files|*.*").
The optional default parameter tells
Tiny Hexer the initial filename to be used when displaying the dialog.
Note: If the user chooses the "Cancel" button in the file
dialog, the script will be terminated if no error handler is set.
Sample:
= select a file and print it via notepad
VAR fname TEXT
LET fname = ASKOPENFILENAME('Print a Text file', 'Text Files (*.txt)|*.txt')
SHELL 'notepad.exe', ('/p "'+fname+'"')
TEXT
ASKSAVEFILENAME([
caption
[,
filter [,
defext [,
default ]]]])
*
more...
less...
Use the ASKSAVEFILENAME() function to let the user select a
filename for file storing.
The optional caption parameter sets
the title of the file selection dialog.
The optional filter parameter tells
Tiny Hexer what file types to display in the file selection dialog.
This parameter is a TEXT string in the form of "Description|File
mask[|...]" (e.g. "Text files|*.txt|All files|*.*").
The optional defext parameter tells
Tiny Hexer which filename extension to use if none is entered in the dialog.
The optional default parameter tells
Tiny Hexer the initial filename to be used when displaying the dialog.
Note: If the user chooses the "Cancel" button in the file
dialog, the script will be terminated if no error handler is set.
Sample:
= save the current selection to disk
VAR selname TEXT
IF CURRENTFILE == ''
ERROR 'No open file'
ENDIF
LET selname = ASKSAVEFILENAME('Save current selection', 'All Files (*.*)|*.*')
!CMD.FileSaveSelection selname
|
|
TEXT
BIN(
number [,
usetype])
more...
less...
Use the BIN() function to convert the ordinal numeric expression
number to a binary representation
consisting of the characters "0" and "1". If the optional parameter
usetype is set to 0, numbers
< 0 are always converted as 64 bits signed values. If set to
1, the type of number is used
to convert negative values. This flag affects the converted
representation of negative values only, positive values are always
calculated using the original data type.
Sample:
MSGBOX (BIN(BYTE(1))):= shows "00000001" (8 bits)
MSGBOX (BIN(WORD(256))):= shows "0000000100000000" (16 bits)
MSGBOX (BIN(LONGWORD(256))):= shows "00000000000000000000000100000000" (32 bits)
MSGBOX (BIN(SIGBYTE(-1))):= shows "1111111111111111111111111111111111111111111111111111111111111111" (64 bits)
MSGBOX (BIN(SIGBYTE(-1),1)):= shows "11111111" (8 bits)
MSGBOX (BIN(SIGWORD(-1),1)):= shows "1111111111111111" (16 bits)
TEXT
BIN2HEX(
strdata [,
swaphalfbytes])
more...
less...
The BIN2HEX() function is used to convert the binary contents of
the expression strdata to their
hexadecimal text representation, i.e. each byte is converted to two
hexadecimal digits.
If the optional paramater swaphalfbytes is set to 1, the order of the
returned values is <low halfbyte><high halfbyte>...,
otherwise the order is <high halfbyte><low halfbyte>...
Sample:
= convert data to hexadecimal digits
VAR txt1 TEXT txt2 TEXT
txt1 = 'ABC'
LET txt2 = BIN2HEX(txt1)
= txt2 now contains '414243'
MSGBOX txt2
LET txt2 = BIN2HEX(txt1, 1)
= txt2 now contains '142434'
MSGBOX txt2
more...
less...
The
BYTE() function is used to convert the expression
expr to the
BYTE data type.
If
expr is a numeric or CHAR
expression, the lowest eight bits of its ordinal value are
returned.
If
expr is of type TEXT, Tiny Hexer
tries to convert the text string to a number. If conversion fails, an
error is raised. If conversion succeeds, the lowest eight bits of the
converted number are returned.
Sample:
= show the ascii value of a char
VAR ch CHAR inp TEXT bt BYTE
REPEAT
inp = INPUT('Enter a character', '', 'A')
UNTIL TEXTLEN(inp) == 1
LET ch = inp
LET bt = BYTE(ch)
MSGBOX ('The ASCII value of '+inp+' is '+TEXT(bt))
more...
less...
The BYTESTRING() function tries to convert the text
text to a byte value.
Sample:
= convert some byte strings
VAR s1 TEXT s2 TEXT s3 TEXT
VAR res LONGWORD
LET s1 = "2.5 GB"
LET s2 = "512k"
LET s3 = "8 MEGABYTE"
LET res = BYTESTRING(s1)
= res contains the value 2.5 * 1024 * 1024 * 1024 = 2684354560
MSGBOX DEC(res)
LET res = BYTESTRING(s2)
= res contains the value 512 * 1024 = 524288
MSGBOX DEC(res)
LET res = BYTESTRING(s3)
= res contains the value 8 * 1024 * 1024 = 8388608
MSGBOX DEC(res)
VALUE
CALL(
target [,
param1,
param2...])
VALUE
#
target [(
param1,
param2...)]
Parameters:
target: the name of a
label in the current script (in the form of
a
TEXT expression if the CALL() construct is used)
param1/2...: optional
expressions that are pushed to the stack
more...
less...
The CALL() function is used to execute a user defined subroutine
in the current script at the label target. The subroutine should return a value using
the RETURN command. This value is used as the function's value.
Contrary to the CALL command, the label's name must be specified using
a textual expression, so the CALL() function is slower than the CALL
command as the position of the label target is looked up from a table at runtime rather
than at compile time. But the function is also more flexible as the
label can be changed at runtime. Note: As of version 1.7 of Tiny
Hexer, you can use the #target
construct to avoid label name lookups at runtime. This construct can
only be used with labels that are already defined.
The CALL() function can have optional parameters that are pushed to the
stack. The subroutine can retrieve those parameters using the POP
command. (Note: Because the stack is a LIFO, the first POP in a
subroutine returns the last parameter, the second POP returns the last
but one parameter...). The subroutine can retrieve the number of
parameters pushed to the stack by reading the ARGC special variable.
Sample:
= SAMPLE 1 = calculating the factorial using recursive function calls
= recursive factorial function
LOCAL factorial
VAR fac SIGQWORD n SIGQWORD
POP n
fac = 1
IF (n > 1)
fac = n * #factorial(n-1)
ENDIF
RETURN fac
ENDLOCAL
VAR num BYTE
@@loop1
num=INPUTNUMBER('Factorial', 'Enter a number between 0 and 20:',20)
= 21! and above do not fit into 63 Bits
IF (num > 20):GOTO loop1:ENDIF
MSGBOX (DEC(num)+'! = '+DEC(#factorial(num)))
END
= SAMPLE 2 = showing the usage of CALL(), ARGC, TYPEOFSTACK, POP, RETURN
INCLUDE 'DEF.MPS'
OPTION GLOBALVARS, 0
= pop a value from the stack, ensure it is text
LOCAL poptext
VAR result TEXT stacktype BYTE
= get the type of the data on stack
stacktype=TYPEOFSTACK:= store the stack data type in a local variable before using it in complex expressions!
IF ((stacktype == SINGLE_DATA) OR (stacktype == COMP_DATA) OR (stacktype == DOUBLE_DATA) OR (stacktype == EXTENDED_DATA))
= handle floating point expressions
VAR ftemp EXTENDED
POP ftemp
result = TEXT(ftemp)
ELSE
IF ((stacktype != CHAR_DATA) AND (stacktype != TEXT_DATA))
= seems to be a number, so pop the number and convert to text
VAR temp SIGQWORD
POP temp
result = DEC(temp)
ELSE
= is text, pop directly from stack
POP result
ENDIF
ENDIF
= return the data as text
RETURN result
ENDLOCAL
LOCAL args
VAR argt TEXT
= check the number of parameters pushed to the stack by the caller
IF ARGC > 0
= pop the value from the stack, ensure it's of type TEXT
argt = #poptext
= pop remaining data to cleanup stack
IF ARGC > 1
LOOP poptext, ARGC-1
ENDIF
ENDIF
RETURN (DEC(argc)+' arguments, last argument: '+argt)
ENDLOCAL
VAR t TEXT
t="I am variable t"
MSGBOX #args:= call the local sub 'args', no parameters
MSGBOX CALL('args','text'):= call the local sub 'args', one text parameter
MSGBOX #args('text',2):= call the local sub 'args', text and numeric parameter
MSGBOX #args('text',8,-3.98):= call the local sub 'args', text, ordinal and float parameter
MSGBOX CALL('args','text',2,'hey!',5.8,t):= call the local sub 'args', mixed parameters
|
|
more...
less...
CEIL() returns the ordinal value of the argument number, rounded towards infinity.
Sample:
MSGBOX (DEC(CEIL(2.0))):= results in "2"
MSGBOX (DEC(CEIL(2.0001))):= results in "3"
MSGBOX (DEC(CEIL(-2.0001))):= results in "-2"
more...
less...
The
CHAR() function is used to convert the expression
expr to the
CHAR data type.
If
expr is a numeric expression, the
lowest eight bits of its ordinal value are converted to a character and
are returned.
If
expr is of type TEXT, the first
character of the string is returned. If the string is empty, an error
is raised.
Sample:
= show the character representing an ascii value
VAR ch CHAR num BYTE inp TEXT
REPEAT
REPEAT
inp = INPUT('Enter an ASCII value between 33 and 127', '', '65')
UNTIL ISNUMBER(inp)
LET num = BYTE(inp)
UNTIL (num > 32) AND (num < 128)
LET ch = CHAR(num)
MSGBOX ('Character: "'+ch+'"')
more...
less...
The
COMP() function is used to convert the expression
expr to the
COMP data type.
If
expr is a numeric or CHAR
expression, its ordinal numeric value is returned.
If
expr is of type TEXT, Tiny Hexer
tries to convert the text string to a 64 bits signed number. If
conversion fails, an error is raised.
Sample:
VAR inp TEXT co COMP
REPEAT
inp = INPUT('Enter a number')
UNTIL ISNUMBER(inp)
LET co = COMP(inp)
MSGBOX ('The number you entered was: '+TEXT(co))
more...
less...
The
COMPARE_END() function returns the position of the last byte
of difference block #
index (first
block is at index
0) after a
file comparison has been executed.
more...
less...
The
COMPARE_START() function returns the position of the first
byte of difference block #
index (first
block is at index
0) after a
file comparison has been executed.
more...
less...
COS() returns the cosine of the argument number (radian).
more...
less...
COT() returns the cotangent of the argument number (radian).
more...
less...
The DATA2TEXT() function is used to store the binary value of
expression expr in a data of type
TEXT.
It e.g. can be used to create tables of multiple numeric values by
storing them in a single TEXT string.
Sample:
= power of 2 table example
INCLUDE 'def.mps'
OPTION GLOBALVARS, 1
VAR ptable TEXT, num SIGQWORD
= store the next power of 2 as SIGQWORD in ptable
LOCAL create_table
CONCAT ptable, DATA2TEXT(SIGQWORD(num))
INC num, num
ENDLOCAL
VAR inp TEXT q SIGQWORD power SIGQWORD
LET num = 1
LET ptable = ''
LOOP create_table 63
REPEAT
REPEAT
REPEAT
LET inp = INPUT('Enter a number between 0 and 62')
UNTIL ISNUMBER(inp)
LET q = SIGQWORD(inp)
UNTIL (q < 63) AND (q >= 0)
= power values are stored as SIGQWORD, so SIGQWORD_SIZE must be used
= to access the correct data
power = TEXT2DATA(ptable, q, SIGQWORD_SIZE)
MSGBOX ( '2 ** '+DEC(q)+' = '+DEC(power))
UNTIL 0
more...
less...
The DATA2TEXTBE() function is used to store the binary value of
expression expr in a data of type TEXT
in BIG ENDIAN format (used e.g. by Motorola CPUs).
It e.g. can be used to create tables of multiple numeric values by
storing them in a single TEXT string.
Sample:
= power of 2 table example
INCLUDE 'def.mps'
OPTION GLOBALVARS, 1
VAR ptable TEXT, num SIGQWORD
= store the next power of 2 as SIGQWORD in ptable
LOCAL create_table
CONCAT ptable, DATA2TEXTBE(SIGQWORD(num))
INC num, num
ENDLOCAL
VAR inp TEXT q SIGQWORD power SIGQWORD
LET num = 1
LET ptable = ''
LOOP create_table 63
REPEAT
REPEAT
REPEAT
LET inp = INPUT('Enter a number between 0 and 62')
UNTIL ISNUMBER(inp)
LET q = SIGQWORD(inp)
UNTIL (q < 63) AND (q >= 0)
= power values are stored as SIGQWORD, so SIGQWORD_SIZE must be used
= to access the correct data
power = TEXT2DATABE(ptable, q, SIGQWORD_SIZE)
MSGBOX ( '2 ** '+DEC(q)+' = '+DEC(power))
UNTIL 0
more...
less...
Use the DEC() function to convert the ordinal numeric expression
number to a textual decimal
representation consisting of the characters "0".."9". Numbers < 0
are prefixed by a "-" (minus) sign.
Sample:
MSGBOX (DEC(BYTE(1))):= shows "1" (8 bits)
MSGBOX (DEC(WORD(256))):= shows "256" (16 bits)
MSGBOX (DEC(LONGWORD(256))):= shows "256" (32 bits, but msbs set to 0)
MSGBOX (DEC(SIGBYTE(-1))):= shows "-1" (8 bits)
MSGBOX (DEC(SIGWORD(-1))):= also shows "-1" (16 bits)
MSGBOX (DEC(LONGWORD(-1))):= shows "4294967295" (32 bits, unsigned)
more...
less...
The DEREF() function is used to retrieve the referenced variable
stored in reference.
The function is used to e.g. pass data of arbitrary data types to a
subroutine. To create references to variables, use the unary reference
operator @.
Sample:
= show data type example
INCLUDE 'def.mps'
OPTION GLOBALVARS, 1
VAR output TEXT
= get a textual data type representation
LOCAL getdatatype
VAR stack VARREF
VAR type SIGBYTE
VAR types TEXT
LET types = <<
none
character
unsigned byte
unsigned word
unsigned long
signed quad
text
file
variable reference
single float
double float
extended float
comp float
signed byte
signed word
signed long
>>
POP stack
LET type = TYPEOF(DEREF(stack))
IF ((type <= SIGLONGWORD_DATA) AND (type >= 0))
RETURN TEXTLINE(types, type)
ENDIF
RETURN "unknown"
ENDLOCAL
LOCAL sub_tp
VAR msg TEXT varn TEXT
LET msg = #getdatatype
POP varn
CONCAT output, (varn+" is of type "+msg+"\n")
ENDLOCAL
VAR charV CHAR, byteV BYTE, wordV WORD, longwordV LONGWORD
VAR sigqwordV SIGQWORD, textV TEXT, fileV FILE, refV VARREF, noneV NONE
VAR singleV SINGLE, doubleV DOUBLE, extendedV EXTENDED, compV COMP
VAR sigbyteV SIGBYTE, sigwordV SIGWORD, siglongwordV SIGLONGWORD
call sub_tp, 'charV', @charV
call sub_tp, 'byteV', @byteV
call sub_tp, 'wordV', @wordV
call sub_tp, 'longwordV', @longwordV
call sub_tp, 'sigqwordV', @sigqwordV
call sub_tp, 'textV', @textV
call sub_tp, 'fileV', @fileV
call sub_tp, 'refV', @refV
call sub_tp, 'noneV', @noneV
call sub_tp, 'singleV', @singleV
call sub_tp, 'doubleV', @doubleV
call sub_tp, 'compV', @compV
call sub_tp, 'extendedV', @extendedV
call sub_tp, 'sigbyteV', @sigbyteV
call sub_tp, 'sigwordV', @sigwordV
call sub_tp, 'siglongwordV', @siglongwordV
TEXTBOX output
|
|
more...
less...
The
DOUBLE() function is used to convert the expression
expr to the
DOUBLE precision floating point data
type.
If
expr is a numeric or CHAR
expression, its numeric value is returned.
If
expr is of type TEXT, Tiny Hexer
tries to convert the text string to a floating point number. If
conversion fails, an error is raised.
Sample:
VAR inp TEXT si SINGLE do DOUBLE ex EXTENDED
REPEAT
inp = INPUT('Enter a floating point value')
UNTIL ISFLOAT(inp)
LET si = SINGLE(inp)
LET do = DOUBLE(inp)
LET ex = EXTENDED(inp)
MSGBOX ('The number you entered was (single precision): '+TEXT(si))
MSGBOX ('The number you entered was (double precision): '+TEXT(do))
MSGBOX ('The number you entered was (extended precision): '+TEXT(ex))
more...
less...
The
ENVPARSE() function expands all environment variables in
string to their actual values.
Environment variables must be enclosed in percent signs (%).
Three special variables do exist:
- %APPPATH%: Expands to the name of the directory where Tiny
Hexer resides
- %DATE%: Expands to the current date
- %TIME%: Expands to the current time
Sample:
= show current date and time
MSGBOX (ENVPARSE('Current Date: %date%, Current Time: %time%'))
TEXT
ESCAPEHTML(
string [,
isunicode
[,
leaveblanks]])
*
more...
less...
The ESCAPEHTML() function escapes all characters in string that have a special meaning/are not
printeable in HTML. This function might be useful when printing
characters like "<", ">" and so on to the structure viewer in raw
mode.
If the optional parameter isunicode is
set to 1, the text in string is
treated as Unicode Little Endian text.
If the optional parameter leaveblanks
is set to 1, blanks (0x20 chars) are not escaped to
' ', so they can lead to line breaks in the html document.
Sample:
INCLUDE 'def.mps'
= make some special characters html friendly
VAR s TEXT
s = ESCAPEHTML("<> &⌐")
= s now contains "<> &©"
MSGBOX s
= leave the blank unescaped
s = ESCAPEHTML("<> &⌐", 0, 1)
= s now contains "<> &©"
MSGBOX s
= now try the unicode version of the euro sign
VAR w TEXT
w = TEXTCONVERT("€", TEXTCONVERT_ANSI, TEXTCONVERT_UNICODE)
w = ESCAPEHTML(w, 1)
= w now contains "€"
MSGBOX w
more...
less...
EXP() returns the constant e raised to the power
x.
more...
less...
The
EXTENDED() function is used to convert the expression
expr to the
EXTENDED precision floating point data
type.
If
expr is a numeric or CHAR
expression, its numeric value is returned.
If
expr is of type TEXT, Tiny Hexer
tries to convert the text string to a floating point number. If
conversion fails, an error is raised.
Sample:
VAR inp TEXT si SINGLE do DOUBLE ex EXTENDED
REPEAT
inp = INPUT('Enter a floating point value')
UNTIL ISFLOAT(inp)
LET si = SINGLE(inp)
LET do = DOUBLE(inp)
LET ex = EXTENDED(inp)
MSGBOX ('The number you entered was (single precision): '+TEXT(si))
MSGBOX ('The number you entered was (double precision): '+TEXT(do))
MSGBOX ('The number you entered was (extended precision): '+TEXT(ex))
BYTE
FILEEXISTS(
filename)
more...
less...
The FILEEXISTS() function returns 1 if the file filename exists, otherwise 0 is returned.
Sample:
VAR fname TEXT
LET fname = INPUT('Enter a filename to open in Tiny Hexer')
IF FILEEXISTS(fname)
!CMD.FileOpen fname
ELSE
ERROR ('File '+fname+' not found')
ENDIF
VALUE
FILEGETPROP(
file,
property)
more...
less...
FILEGETPROP() is used to retrieve a
property of a special
file.
The data type of the returned value depends on the property.
List of available properties
Sample:
VAR ed FILE, val BYTE
= open the current editor window
LET ed = FILEOPEN('::current', 'r')
= get bytes per row
LET val = FILEGETPROP(ed, 'BytesPerRow')
= close the file
FILECLOSE ed
= show the BytesPerRow property
MSGBOX ('Current editor displays '+DEC(val)+' Bytes per row')
FILE
FILEOPEN(
filename,
mode)
more...
less...
Use
FILEOPEN() to attach file
filename to a FILE type variable.
The
mode parameter tells Tiny Hexer
Script how to open the file and what access to grant to the file's
contents. This parameter must be a combination of one or more of the
following characters:
- "c": always create the file, erase its contents if it
already exists. This mode flag also implies write access to the
file
- "r": grant read access to the file's contents
(default)
- "w": grant write access to the file's contents
Special Files:
In Tiny Hexer there are numerous special files. To distinguish special
files from ordinary files, the
filename parameter must be start with a double
colon
"::". The following special files exist in Tiny Hexer:
- "::Clipboard": open clipboard contents (CF_TEXT format by
default, see also Clipboard
property)
- "::Browser": open the "Structure viewer" browser window, so you can
write text to the browser. Note: The mode parameter must be
set to "c". You cannot read from this file, and also random
write access to this file is not possible, only sequential write
access is supported
- "::Buffer":
creates an in-memory buffer for storing temporaray data. The file
mode of such files is always set to READ/WRITE
- "::New": open a new editor window and get access to this
editor's data
- "::Current": open a handle to the data of the currently
active editor. If another editor window becomes active, the file
remains attached to the editor which was active at the time the file
has been opened
- "::Editor": open a handle to the data of the currently
active editor. If another editor window becoms active, the file will
be attached to the newly activated editor.
- "::<filename>": attaches the file to the editor data
whose window caption matches <filename>
Sample:
= sample: read a file from disk and write its contents to a new
= editor window, xoring each byte by 255
VAR ed FILE, f FILE, b BYTE sz LONGWORD lp LONGWORD
= open the file on disk (readonly "r")
LET f = FILEOPEN(ASKOPENFILENAME('Select a file'), 'r')
= open a new editor window
LET ed = FILEOPEN('::new', 'c')
LET sz = FILESIZE(f)
LET lp = 0
= set datasize of editor to file's size
FILESETPROP ed, 'Size', sz
= Changing the size sets the file pointer to eof, so reset
FILESEEK ed, 0
= read and transform the file's contents and write the data to the editor
WHILE FILEREAD(f, @b)
SHOWPROGRESS sz, lp
INC lp, 1
LET b = b XOR 255
FILEWRITE ed, b
ENDWHILE
= close the file handles
FILECLOSE ed
FILECLOSE f
|
|
more...
less...
The FILEPOS() returns the current position pointer of
file.
Sample:
INCLUDE 'def.mps'
VAR Position LONGWORD mpth FILE
= open tiny hexer itself in a new editor window
!CMD.FileOpen ENVPARSE('%apppath%\mpth.exe')
= attach a file to the editor, only read access is needed
mpth=FILEOPEN('::current', 'r')
Position=FILEPOS(mpth)
= show start position (0)
MSGBOX ("Position at start of file (= 0): "+DEC(Position)), (MB_OK OR MB_ICONINFORMATION)
= seek to file end
FILESEEK mpth, 0, FILE_END
= set cursor to end of file
!CMD.EditGoto '>0'
Position=FILEPOS(mpth)
= show end position (0)
MSGBOX ("Position at end of file (= file size): "+DEC(Position)), (MB_OK OR MB_ICONINFORMATION)
LONGWORD
FILEREAD(
file,
buffer [,
count])
more...
less...
Use the FILEREAD() function to read data from the file
file into the variable referenced by
buffer.
The optional count parameter tells
Tiny Hexer Script how many bytes of data are to be read. If this
parameter is omitted, the type of the variable referenced by
buffer defines the amount of data to
be read (BYTE, CHAR: 1 Byte, WORD: 2 Bytes, LONGWORD: 4 Bytes,
SIGQWORD: 8 Bytes, TEXT: reads from the file until EOF or a 0x00 byte
is found).
FILEREAD() returns the actual amount of data (in Bytes) that was read
from the file.
Sample:
VAR f FILE, wholefile TEXT, amount LONGWORD
= open the file c:\boot.ini for reading
LET f = FILEOPEN('c:\boot.ini', 'r')
= read up to 500000 bytes from the file
amount=FILEREAD(f, @wholefile, 500000)
= close the file handle
FILECLOSE f
= tell how many data has been read
MSGBOX ("Bytes read: "+DEC(amount))
more...
less...
Use the FILEREADBE() function to read data from the file
file into the variable referenced by
buffer if the file's contents are
stored in BIG ENDIAN format (e.g. on Motorola CPUs).
The type of the variable referenced by buffer defines the amount of data to be read
(BYTE, CHAR: 1 Byte, WORD: 2 Bytes, LONGWORD: 4 Bytes, SIGQWORD: 8
Bytes, TEXT: reads from the file until EOF or a 0x00 byte is
found).
If the variable referenced by buffer
is of type WORD, LONGWORD or SIGQWORD, the data is swapped after
reading (e.g. LONGWORD = Byte 0 becomes Byte 3, Byte 1 becomes Byte 2,
Byte 2 becomes Byte 1 and Byte 3 becomes Byte 0). On other data types,
the function is similar to the FILEREAD() function (except for the
missing count parameter).
FILEREADBE() returns the actual amount of data (in Bytes) that was read
from the file.
more...
less...
The FILES() function returns the filename of the editor child
#index (first file is at index
0). Use the FILE_COUNT special variable to get the number of
files currently opened in Tiny Hexer.
Sample:
= enumerate all open editor files
VAR d LONGWORD
VAR ed TEXT
d=FILE_COUNT
IF d == 0
MSGBOX "No files open"
ELSE
LOOP enum d
ENDIF
END
@@enum
ed=FILES(loop)
MSGBOX ("File "+DEC(loop+1)+": "+ed)
RETURN
more...
less...
The FILESIZE() returns the size (in Bytes) of file.
Sample:
INCLUDE 'def.mps'
VAR Size LONGWORD mpth FILE
= open tiny hexer itself in a new editor window
!CMD.FileOpen ENVPARSE('%apppath%\mpth.exe')
= attach a file to the editor, only read access is needed
mpth=FILEOPEN('::current', 'r')
Size=FILESIZE(mpth)
MSGBOX ("Size of file: "+DEC(Size)), (MB_OK OR MB_ICONINFORMATION)
Parameters:
file: a
variable of type
FILE
data: an
expression of type TEXT, CHAR, BYTE, WORD, LONGWORD
or SIGQWORD
more...
less...
Use the FILEWRITE() function to write the contents of
data to the file file.
The type of the data expression
defines the amount of data to be written to the file (BYTE, CHAR: 1
Byte, WORD: 2 Bytes, LONGWORD: 4 Bytes, SIGQWORD: 8 Bytes, TEXT: length
of the text value).
FILEWRITE() returns the actual amount of data (in Bytes) that has been
written.
Sample:
INCLUDE 'def.mps'
VAR f FILE, dw LONGWORD, written LONGWORD, fname TEXT l TEXT
LET fname = 'c:\test.dat'
= enter a number
REPEAT
l = INPUT('Enter a number')
UNTIL ISNUMBER(l)
LET dw=LONGWORD(l)
= create the file
LET f = FILEOPEN(fname, 'c')
= write the number in binary format
LET written=FILEWRITE(f, dw)
= close the file handle
FILECLOSE f
= check if all data has been written
IF written != LONGWORD_SIZE
ERROR "Not all data could be written!"
ENDIF
Parameters:
file: a
variable of type
FILE
data: an
expression of type TEXT, CHAR, BYTE, WORD, LONGWORD
or SIGQWORD
more...
less...
Use the FILEWRITEBE() function to write the contents of
data to the file file if the file's contents should be stored in
BIG ENDIAN format (e.g. on Motorola CPUs).
The type of the data expression
defines the amount of data to be written to the file (BYTE, CHAR: 1
Byte, WORD: 2 Bytes, LONGWORD: 4 Bytes, SIGQWORD: 8 Bytes, TEXT: length
of the text value).
If data is of type WORD, LONGWORD or
SIGQWORD, the data is swapped before writing (e.g. LONGWORD = Byte 0
becomes Byte 3, Byte 1 becomes Byte 2, Byte 2 becomes Byte 1 and Byte 3
becomes Byte 0). On other data types, the function is similar to the
FILEWRITE() function.
FILEWRITEBE() returns the actual amount of data (in Bytes) that has
been written.
more...
less...
FLOATTOIBM4() converts the value of float into the ibm single precision floating point
format. You cannot use the resulting SIGLONGWORD value for calculation
but to store floating point values in ibm format in a file.
Sample:
VAR e EXTENDED
VAR i4 SIGLONGWORD i8 SIGQWORD:= variables to store ibm format floating point values
LET e = 1.23e-12
LET i4 = FLOATTOIBM4(e):= now i4 stores a ibm single floating point value
LET e = IBM4TOFLOAT(i4):= convert back (loses some precision due to single precision ibm format)
MSGBOX TEXT(e)
LET e = 1.23e-12
LET i8 = FLOATTOIBM8(e):= now i8 stores a ibm double floating point value
LET e = IBM8TOFLOAT(i8):= convert back (loses less precision due to double precision ibm format)
MSGBOX TEXT(e)
more...
less...
FLOATTOIBM8() converts the value of float into the ibm double precision floating point
format. You cannot use the resulting SIGQWORD value for calculation but
to store floating point values in ibm format in a file.
Sample:
VAR e EXTENDED
VAR i4 SIGLONGWORD i8 SIGQWORD:= variables to store ibm format floating point values
LET e = 1.23e-12
LET i4 = FLOATTOIBM4(e):= now i4 stores a ibm single floating point value
LET e = IBM4TOFLOAT(i4):= convert back (loses some precision due to single precision ibm format)
MSGBOX TEXT(e)
LET e = 1.23e-12
LET i8 = FLOATTOIBM8(e):= now i8 stores a ibm double floating point value
LET e = IBM8TOFLOAT(i8):= convert back (loses less precision due to double precision ibm format)
MSGBOX TEXT(e)
more...
less...
FLOOR() returns the ordinal value of the argument number, rounded towards -infinity.
Sample:
MSGBOX (DEC(FLOOR(2.0))):= results in "2"
MSGBOX (DEC(FLOOR(2.9999))):= results in "2"
MSGBOX (DEC(FLOOR(-2.9999))):= results in "-3"
more...
less...
FRAC() returns the signed fractional part of the floating point
value of number.
Sample:
MSGBOX (TEXT(FRAC(2))):= results in "0"
MSGBOX (TEXT(FRAC(2.9999))):= results in "0.9999"
MSGBOX (TEXT(FRAC(-2.9999))):= results in "-0.9999"
GUI functions for user defined dialogs
TEXT
HEX(
number [,
usetype])
more...
less...
Use the HEX() function to convert the ordinal numeric expression
number to a hexadecimal representation
consisting of the characters "0".."9" and "A".."F". If the optional
parameter usetype is set to 0,
numbers < 0 are always converted as 64 bits signed values. If set to
1, the type of number is used
to convert negative values. This flag affects the converted
representation of negative values only, positive values are always
calculated using the original data type.
Sample:
MSGBOX (HEX(BYTE(1))):= shows "01" (8 bits)
MSGBOX (HEX(WORD(256))):= shows "0100" (16 bits)
MSGBOX (HEX(LONGWORD(256))):= shows "00000100" (32 bits)
MSGBOX (HEX(SIGBYTE(-1))):= shows "FFFFFFFFFFFFFFFF" (64 bits)
MSGBOX (HEX(SIGBYTE(-1),1)):= shows "FF" (8 bits)
MSGBOX (HEX(SIGWORD(-1),1)):= shows "FFFF" (16 bits)
TEXT
HEX2BIN(
strhex [,
swaphalfbytes])
more...
less...
The HEX2BIN() function is used to convert a hexadecimal data
representation in strhex to binary
data. Characters in strhex that are no
hexadecimal digits are skipped.
If the optional paramater swaphalfbytes is set to 1, the order of the
hexadecimal digits is <low halfbyte><high halfbyte>...,
otherwise the order is <high halfbyte><low halfbyte>...
Sample:
= convert hexadecimal digits to data
VAR txt1 TEXT txt2 TEXT
txt1 = '42 43 45'
LET txt2 = HEX2BIN(txt1)
= txt2 now contains 'BCE'
MSGBOX txt2
LET txt2 = HEX2BIN(txt1, 1)
= txt2 now contains '$4T'
MSGBOX txt2
more...
less...
The HEX2NUM() function is used to convert the TEXT expression
digits (consisting of hexadecimal
digits) to a number.
Sample:
VAR i SIGQWORD
LET i=HEX2NUM('FCE2')
= i is 64738 now
MSGBOX DEC(i)
more...
less...
IBM4TOFLOAT() converts the value of the ibm single precision
float format value stored in the ibm4val pseudo SIGLONGWORD into an extended IEEE
floating point value.
Sample:
VAR e EXTENDED
VAR i4 SIGLONGWORD i8 SIGQWORD:= variables to store ibm format floating point values
LET e = 1.23e-12
LET i4 = FLOATTOIBM4(e):= now i4 stores a ibm single floating point value
LET e = IBM4TOFLOAT(i4):= convert back (loses some precision due to single precision ibm format)
MSGBOX TEXT(e)
LET e = 1.23e-12
LET i8 = FLOATTOIBM8(e):= now i8 stores a ibm double floating point value
LET e = IBM8TOFLOAT(i8):= convert back (loses less precision due to double precision ibm format)
MSGBOX TEXT(e)
more...
less...
IBM8TOFLOAT() converts the value of the ibm double precision
float format value stored in the ibm4val pseudo SIGQWORD into an extended IEEE
floating point value.
Sample:
VAR e EXTENDED
VAR i4 SIGLONGWORD i8 SIGQWORD:= variables to store ibm format floating point values
LET e = 1.23e-12
LET i4 = FLOATTOIBM4(e):= now i4 stores a ibm single floating point value
LET e = IBM4TOFLOAT(i4):= convert back (loses some precision due to single precision ibm format)
MSGBOX TEXT(e)
LET e = 1.23e-12
LET i8 = FLOATTOIBM8(e):= now i8 stores a ibm double floating point value
LET e = IBM8TOFLOAT(i8):= convert back (loses less precision due to double precision ibm format)
MSGBOX TEXT(e)
BYTE
INIREAD(
filename,
section,
key,
buffer)
more...
less...
Use the INIREAD() function to read values from ini-style text
files.
filename is the name of the ini
file.
section is the name of the section in
the ini file ([section] lines).
key is the name of the key in the ini
file (the part to the left of the equal sign).
buffer is a reference to a variable
that will contain the value read from the ini file.
If the specified key could be read from the ini file, 1 is returned.
Otherwise 0 is returned.
Sample:
DEF ini "d:\\mpthtest.ini"
= write some data to the ini file
iniwrite ini, "section1", "key1", 2
iniwrite ini, "section2", "key2", "abc"
VAR val LONGWORD val_t TEXT
= try to read section1/key1 as longword
IF INIREAD(ini, "section1", "key1", @val)
MSGBOX ('Value of section1/key1: '+DEC(val))
ELSE
ERROR ('Cannot read section1/key1 value from '+ini)
ENDIF
= try to read section2/key2 as text
IF INIREAD(ini, "section2", "key2", @val_t)
MSGBOX ('Value of section2/key2: '+val_t)
ELSE
ERROR ('Cannot read section2/key2 value from '+ini)
ENDIF
|
|
TEXT
INPUT(
prompt)
TEXT
INPUT(
caption,
prompt [,
default])
*
more...
less...
more...
less...
|
|
more...
less...
INT() returns the signed integral part of the floating point
value of number, that is the
fractional part is stripped off.
Sample:
MSGBOX (TEXT(INT(2.005))):= results in "2"
MSGBOX (TEXT(INT(2.9999))):= results in "2"
MSGBOX (TEXT(INT(-2.9999))):= results in "-2"
more...
less...
Use the ISFLOAT() function to determine whether the TEXT
value is a valid floating point number
representation (that is value solely
consists of decimal digits and optionally decimal comma, minus sign and
exponential sign ("E"). If value is a
valid floating point number, 1 is returned, otherwise 0 is returned.
Sample:
VAR inp TEXT
REPEAT
inp=INPUT('Enter a floating point value')
IF not ISFLOAT(inp)
MSGBOX (inp+" is not a valid floating point number!")
ENDIF
UNTIL ISFLOAT(inp)
MSGBOX (INP+" = "+TEXT(EXTENDED(INP)))
more...
less...
Use the ISHEX() function to determine whether the TEXT
value is a valid hexadecimal number
(that is value solely consists of
hexadecimal digits, it may optionally be prefixed by "0x"), max. 64
bits. If value is a valid hexadecimal
number, 1 is returned, otherwise 0 is returned.
Sample:
VAR inp TEXT
REPEAT
inp=INPUT('Enter a hexadecimal value')
IF not ISHEX(inp)
MSGBOX (inp+" is not a valid hexadecimal number!")
ENDIF
UNTIL ISHEX(inp)
more...
less...
Use the ISNUMBER() function to determine whether the TEXT
value is a valid ordinal
numeric representation either in decimal (e.g. '100'), hexadecimal
(e.g. '0xff') or octal (e.g. '755o') notation (max. 64 bits wide). If
value is a valid number, 1 is
returned, otherwise 0 is returned.
Sample:
VAR inp TEXT
REPEAT
inp=INPUT('Enter a number')
IF not ISNUMBER(inp)
MSGBOX (inp+" is not a number!")
ENDIF
UNTIL ISNUMBER(inp)
more...
less...
LOG10() returns the base 10 logarithm of x.
more...
less...
LOGN() returns the natural logarithm of x.
more...
less...
The
LONGWORD() function is used to convert the expression
expr to the
LONGWORD data type.
If
expr is a numeric or CHAR
expression, the lowest 32 bits of its ordinal value are returned.
If
expr is of type TEXT, Tiny Hexer
tries to convert the text string to a number. If conversion fails, an
error is raised. If conversion succeeds, the lowest 32 bits of the
converted number are returned.
In earlier versions of Tiny Hexer, this function was called DWORD().
This alias is deprecated.
Sample:
= convert a text to a longword number
VAR inp TEXT dw LONGWORD
REPEAT
inp = INPUT('Enter a numeric value')
UNTIL ISNUMBER(inp)
LET dw = LONGWORD(inp)
= output hexadecimal
MSGBOX ('The number you entered was (hex): '+HEX(dw))
more...
less...
The MAX() function returns the greater of the two parameters
i1 and i2 or f1 and
f2, respectively.
Sample:
MSGBOX DEC(MAX(1,2)):= results in "2"
MSGBOX TEXT(MAX(1.5,2.5)):= results in "2.5"
more...
less...
The MIN() function returns the lesser of the two parameters
i1 and i2 or f1 and
f2, respectively.
Sample:
MSGBOX DEC(MIN(1,2)):= results in "1"
MSGBOX TEXT(MIN(1.5,2.5)):= results in "1.5"
LONGWORD
MSGBOX(
message [,
flags [,
title]])
more...
less...
MSGBOX() opens a dialog displaying the text
message.
The optional
flags parameter tells
Windows to change the behaviour and/or appearance of the dialog (see
MSGBOX
flags).
MSGBOX() returns the value of the button the user has selected:
- IDOK (= 1): "OK" button has been selected
- IDCANCEL (= 2): "Cancel" button has been selected
- IDABORT (= 3): "Abort" button has been selected
- IDRETRY (= 4): "Retry" button has been selected
- IDIGNORE (= 5): "Ignore" button has been selected
- IDYES (= 6): "Yes" button has been selected
- IDNO (= 7): "No" button has been selected
- IDTRYAGAIN (= 10): "Try Again" button has been
selected
- IDCONTINUE (= 11): "Continue" button has been
selected
The optional
title parameter modifies
the title bar caption of the message dialog.
Sample:
INCLUDE 'def.mps'
VAR btn BYTE
btn=MSGBOX('Click a button', MB_CANCELTRYCONTINUE OR MB_ICONASTERISK)
IF btn==IDCANCEL
MSGBOX "'Cancel' button has been selected"
ELSE
IF btn==IDCONTINUE
MSGBOX "'Continue' button has been selected"
ELSE
MSGBOX "'Retry' button has been selected"
ENDIF
ENDIF
|
|
TEXT
OCT(
number [,
usetype])
more...
less...
Use the OCT() function to convert the ordinal numeric expression
number to a octal representation
consisting of the characters "0".."7". If the optional parameter
usetype is set to 0, numbers
< 0 are always converted as 64 bits signed values. If set to
1, the type of number is used
to convert negative values. This flag affects the converted
representation of negative values only, positive values are always
calculated to the shortest possible length.
Sample:
MSGBOX (OCT(BYTE(1))):= shows "1" (8 bits)
MSGBOX (OCT(WORD(256))):= shows "400" (16 bits)
MSGBOX (OCT(LONGWORD(256))):= shows "400" (32 bits, but msbs set to 0)
MSGBOX (OCT(SIGBYTE(-1))):= shows "1777777777777777777777" (64 bits)
MSGBOX (OCT(SIGBYTE(-1),1)):= shows "377" (8 bits)
MSGBOX (OCT(SIGWORD(-1),1)):= shows "177777" (16 bits)
more...
less...
ODD() returns 1 if the value of x is odd, 0 if it's even or 0.
more...
less...
The
PARAMS() function returns the contents of the parameter
#
index (first parameter is at index
0) passed to the script when it's started by a
tools menu item.
Sample:
= save this script under c:\script1.mps
= start of script 1
= execute script 2 and pass two parameters to it
= parameters are separated by blanks or comma
= multiple parameters enclosed in double quotes are used as single parameters
!CMD.ToolsExecuteScript "c:\\script2.mps", '"First argument", "Second argument"'
END
= end of script 1
= save this script under c:\script2.mps
= start of script 2
VAR lp LONGWORD, param TEXT
= show all parameters
lp=0
WHILE lp < PARAM_COUNT
param=PARAMS(lp)
MSGBOX ("Parameter "+DEC(lp+1)+": "+param)
INC lp, 1
ENDWHILE
END
= end of script 2
more...
less...
The
POSITIONS() function returns the value of the entry
#
index in the
position list (first entry is at index
0,
an index value of
-1 returns the value of the entry that has the
focus.)
Sample:
= show the value of the currently focused entry in the position list
VAR val SIGQWORD
val=POSITIONS(-1)
IF (val == -1)
ERROR "No entry selected in the position list"
ELSE
MSGBOX ("Value of the focused entry in the position list: "+TEXT(LONGWORD(val)))
ENDIF
more...
less...
The
POSITION_ADD() function is used to add a position
value to the
position list. The optional parameter
length is used to add a selection
length. The function returns the index of the new entry in the position
list.
Sample:
= add an entry to the position list and select it
VAR index LONGWORD, wasselected BYTE, newpos LONGWORD
= query a value to be added to the position list
newpos=INPUTNUMBER("Enter a position value to be added to the position list")
IF (newpos == 0):END:ENDIF
index=POSITION_ADD(newpos)
= select and focus the newly added item
wasselected = POSITION_SELECTED(index, 1, 1)
BYTE
POSITION_SELECTED(
index
[,
doselect [,
dosetfocus]])
*
more...
less...
The
POSITION_SELECTED() function is used to tell whether entry
#
index of the
position list is currently selected. The function
returns
1 if the entry is selected and
0 otherwise (the
first entry is at index
0, an index value of
-1 acts on
the entry that has the focus.)
The optional
doselect parameter can be
used to change the entry's selection state (
1 selects the item,
0 deselects it).
The optional
dosetfocus parameter,
when set to
1, makes that entry the focused entry in the
position list.
Sample:
= add an entry to the position list and select it
VAR newpos SIGQWORD, index LONGWORD, wasselected BYTE
= query a value to be added to the position list
newpos=SIGQWORD(INPUT("", "Enter a position value to be added to the position list","-1"))
IF (newpos < 0):END:ENDIF
index=POSITION_ADD(newpos)
= select and focus the newly added position
wasselected = POSITION_SELECTED(index, 1, 1)
more...
less...
The RANDOM() function returns an ordinal random number within
the range 0..max-1.
Sample:
MSGBOX "Guess a number game", 64
VAR number BYTE, entered BYTE
LABEL start
= randomly choose a number between 1 and 10
LET number = RANDOM(10)+1
LABEL loop
LET entered = BYTE(INPUTNUMBER('Enter a number between 1 and 10'))
IF entered == number
MSGBOX 'Right!'
ELSE
IF number < entered
MSGBOX ('My number is less than '+DEC(entered))
ELSE
MSGBOX ('My number is greater than '+DEC(entered))
ENDIF
GOTO loop
ENDIF
GOTO start
BYTE
REGREAD(
key,
name,
buffer)
more...
less...
Use the REGREAD() function to read values from the
registry.
key is the name of the registry key.
by default, REGREAD() reads values from the HKEY_CURRENT_USER root key.
to select another root key, prefix key
by the name of the root key (e.g.
'HKEY_LOCAL_MACHINE\Software...').
Note: To read data from Tiny Hexer's settings database rather
than from the registry, use the 'HKEY_SETTINGS' pseudo root
key.
name is the name of the value in the
given registry key.
buffer is a reference to a variable
that will contain the value read from the registry.
If the specified value could be read from the registry, 1 is returned,
otherwise 0 is returned.
Sample:
DEF reg "HKEY_CURRENT_USER\\Temporary Test Key"
= write some data to the registry
regwrite reg, "name1", 2
regwrite reg, "name2", "abc"
VAR val LONGWORD val_t TEXT
= try to read name1 as longword
IF REGREAD(reg, "name1", @val)
MSGBOX ('Value of name1: '+TEXT(val))
ELSE
ERROR ('Cannot read name1 value from '+reg)
ENDIF
= try to read name2 as text
IF REGREAD(reg, "name2", @val_t)
MSGBOX ('Value of name2: '+val_t)
ELSE
ERROR ('Cannot read name2 value from '+reg)
ENDIF
= delete temporary key
regwrite reg
|
|
more...
less...
ROUND() returns the ordinal value of the argument number, rounded to the nearest ordinal
number.
Sample:
MSGBOX (DEC(ROUND(2.499))):= results in "2"
MSGBOX (DEC(ROUND(2.501))):= results in "3"
MSGBOX (DEC(ROUND(-2.499))):= results in "-2"
MSGBOX (DEC(ROUND(-2.501))):= results in "-3"
TEXT
SELECTEDITORFILE(
title,
prompt [,
files [,
multiselect [,
default]]])
*
more...
less...
The SELECTEDITORFILE() function pops up a dialog that allows you
to select currently opened editor files from a list.
SELECTEDITORFILE() returns the name (or newline sparated list of
names) that has been selected in the dialog.
title is the caption of the dialog,
prompt is displayed as a hint label in
the dialog.
If the optional files parameter is
used and contains file names (separated by newline characters), the
dialog only shows these filenames, otherwise all files currently opened
are displayed.
If the optional multiselect parameter
is set to a value different from zero, the dialog allows to select
multiple files (the function returns multiple file names separated by
newline characters).
The optional default value is used to
specify a preselection when the dialog is displayed: set it to
-1 to select all files by default (only if multiselect is enabled), set it to 0 for no
preselection or set it to a line index into the files lines "array" (1-based).
Sample:
= show overall size of selected files
VAR selected TEXT
= set decimal output
INCLUDE 'def.mps'
selected = SELECTEDITORFILE('Overall file size', 'Select some files:', '', 1, -1)
VAR amount LONGWORD size SIGQWORD index LONGWORD f FILE
= get the number of returned files
amount = TEXTLINECOUNT(selected)
IF (amount)
size = 0: = reset size
index = 0: = reset index
WHILE (index < amount)
= open file to get size, filenames are separated by newlines
= so get the current line via TEXTLINE()
f = FILEOPEN(('::'+TEXTLINE(selected, index)), 'r')
INC index, 1
= retrieve the size of the file and add to the overall size
INC size, FILESIZE(f)
FILECLOSE f
ENDWHILE
= show the overall size
MSGBOX ("Number of files:"+DEC(amount)+"\nOverall file size: "+DEC(size)), MB_ICONINFORMATION
ENDIF
|
|
LONGWORD
SHELL(
program
[,
parameters [,
show [,
directory
[,
output]]]])
more...
less...
The SHELL() function is used to execute the external application
program. Script execution is always
stopped until program has finished.
SHELL() returns the exit code of the program, if it cannot be executed,
0xFFFFFFFF is returned.
Optionally the command line arguments parameters can be passed to program.
Additionally you can tell Tiny Hexer Script to show or hide the
external application using the show
parameter (SW_HIDE, SW_SHOW...)
The optional directory parameter tells
Windows to set program's current
directory.
The optional output parameter is a
reference to a TEXT variable that will contain the output of
program after its execution.
Sample:
VAR exitcode LONGWORD num LONGWORD fname TEXT
num=INPUTNUMBER('Enter an exitcode')
VAR f FILE
= create a temp. batch file
fname=ENVPARSE('%temp%')+'\shelltest1.bat'
f=FILEOPEN(fname,'c')
FILEWRITE f, ('@echo Exiting with code '+DEC(num)+"\r\n")
FILEWRITE f, ('@exit '+DEC(num)+"\r\n")
FILECLOSE f
= run the created batch
exitcode=SHELL(fname)
FILEDELETE (fname)
= show the exitcode
MSGBOX ('Exitcode of '+fname+': '+DEC(exitcode)+" (wanted: "+DEC(num)+")")
|
|
more...
less...
The
SIGBYTE() function is used to convert the expression
expr to the
SIGBYTE data type. As SIGBYTE is a signed
numeric data type, it can only store 7 bits of data though it is a 8
bits wide data type.
If
expr is a numeric or CHAR
expression, the lowest 7 bits of its ordinal value and its sign are
returned.
If
expr is of type TEXT, Tiny Hexer
tries to convert the text string to a number. If conversion fails, an
error is raised. If conversion succeeds, the lowest 7 bits of the
converted number and its sign are returned are returned.
Sample:
VAR inp TEXT
REPEAT
REPEAT
inp = INPUT('', 'Enter a negative integral number', '-1')
UNTIL ISNUMBER(inp)
UNTIL (SIGBYTE(inp) < 0)
more...
less...
The
SIGLONGWORD() function is used to convert the expression
expr to the
SIGLONGWORD data type. As SIGLONGWORD
is a signed numeric data type, it can only store 31 bits of data though
it is a 32 bits wide data type.
If
expr is a numeric or CHAR
expression, the lowest 31 bits of its ordinal value and its sign are
returned.
If
expr is of type TEXT, Tiny Hexer
tries to convert the text string to a number. If conversion fails, an
error is raised. If conversion succeeds, the lowest 31 bits of the
converted number and its sign are returned are returned.
Sample:
VAR inp TEXT
REPEAT
REPEAT
inp = INPUT('', 'Enter a negative integral number', '-1')
UNTIL ISNUMBER(inp)
UNTIL (SIGLONGWORD(inp) < 0)
more...
less...
The SIGN() function returns the sign of the parameter
ivalue or fvalue, respectively.
Sample:
MSGBOX DEC(SIGN(-5)):= results in "-1"
MSGBOX DEC(SIGN(-0)):= results in "0"
MSGBOX DEC(SIGN(5)):= results in "1"
MSGBOX TEXT(SIGN(-5.5)):= results in "-1"
MSGBOX TEXT(SIGN(-0.0)):= results in "0"
MSGBOX TEXT(SIGN(5.5)):= results in "1"
more...
less...
The
SIGQWORD() function is used to convert the expression
expr to the
SIGQWORD data type. As SIGQWORD is a
signed numeric data type, it can only store 63 bits of data though it
is a 64 bits wide data type.
If
expr is a numeric or CHAR
expression, the lowest 63 bits of its ordinal value and its sign are
returned.
If
expr is of type TEXT, Tiny Hexer
tries to convert the text string to a number. If conversion fails, an
error is raised. If conversion succeeds, the lowest 63 bits of the
converted number and its sign are returned are returned.
In earlier versions of Tiny Hexer, this function was called QWORD().
This alias is deprecated.
Sample:
VAR inp TEXT
REPEAT
REPEAT
inp = INPUT('', 'Enter a negative integral number', '-1')
UNTIL ISNUMBER(inp)
UNTIL (SIGQWORD(inp) < 0)
more...
less...
The
SIGWORD() function is used to convert the expression
expr to the
SIGWORD data type. As SIGWORD is a signed
numeric data type, it can only store 15 bits of data though it is a 16
bits wide data type.
If
expr is a numeric or CHAR
expression, the lowest 15 bits of its ordinal value and its sign are
returned.
If
expr is of type TEXT, Tiny Hexer
tries to convert the text string to a number. If conversion fails, an
error is raised. If conversion succeeds, the lowest 15 bits of the
converted number and its sign are returned are returned.
Sample:
VAR inp TEXT
REPEAT
REPEAT
inp = INPUT('', 'Enter a negative integral number', '-1')
UNTIL ISNUMBER(inp)
UNTIL (SIGWORD(inp) < 0)
more...
less...
SIN() returns the sine of the argument number (radian).
more...
less...
The
SINGLE() function is used to convert the expression
expr to the
SINGLE precision floating point data
type.
If
expr is a numeric or CHAR
expression, its numeric value is returned.
If
expr is of type TEXT, Tiny Hexer
tries to convert the text string to a floating point number. If
conversion fails, an error is raised.
Sample:
VAR inp TEXT si SINGLE do DOUBLE ex EXTENDED
REPEAT
inp = INPUT('Enter a floating point value')
UNTIL ISFLOAT(inp)
LET si = SINGLE(inp)
LET do = DOUBLE(inp)
LET ex = EXTENDED(inp)
MSGBOX ('The number you entered was (single precision): '+TEXT(si))
MSGBOX ('The number you entered was (double precision): '+TEXT(do))
MSGBOX ('The number you entered was (extended precision): '+TEXT(ex))
more...
less...
SQRT() returns the square root of x.
more...
less...
The TAG_LEN() function returns the length tag of the variable
referenced by ref.
If the referenced variable is not tagged, -1 is returned.
Sample:
= enable variable tagging
OPTION READTAGS, 1
VAR f FILE, t TEXT, msg TEXT
= open tiny hexer itself
f=FILEOPEN(ENVPARSE('%apppath%\mpth.exe'),'r')
= locate a specific position
FILESEEK f, 986284
= read text from file with automatic tagging
FILEREAD f, t, 9
= t is now tagged with file position and data length
FILECLOSE f
msg='Data read from file: "'+t+'"'+"\n\r"
CONCAT msg, 'At position: '+DEC(TAG_POS(@t))+"\n\r"
CONCAT msg, 'Data length: '+DEC(TAG_LEN(@t))+"\n\r"
MSGBOX msg
more...
less...
The TAG_POS() function returns the position tag of the variable
referenced by ref.
If the referenced variable is not tagged, -1 is returned.
Sample:
= enable variable tagging
OPTION READTAGS, 1
VAR f FILE, t TEXT, msg TEXT
= open tiny hexer itself
f=FILEOPEN(ENVPARSE('%apppath%\mpth.exe'),'r')
= locate a specific position
FILESEEK f, 986284
= read text from file with automatic tagging
FILEREAD f, t, 9
= t is now tagged with file position and data length
FILECLOSE f
msg='Data read from file: "'+t+'"'+"\n\r"
CONCAT msg, 'At position: '+DEC(TAG_POS(@t))+"\n\r"
CONCAT msg, 'Data length: '+DEC(TAG_LEN(@t))+"\n\r"
MSGBOX msg
more...
less...
TAN() returns the tangent of the argument number (radian).
more...
less...
The
TEXT() function is used to convert the expression
expr to the
TEXT data type.
If
expr is a numeric expression, its
value is converted to a textual represention; the conversion format
depends on the values of the NUMBER_RADIX, NUMBER_PREFIX and
NUMBER_SUFFIX special variables if the number is ordinal, when
converting floating point numbers, they are always converted using base
(radix) 10.
If
expr is of type TEXT or CHAR, a
copy of the string is returned.
Sample:
= show different number to text conversions
VAR number WORD txt TEXT
number=64738
= binary (radix 2)
NUMBER_RADIX=2
NUMBER_PREFIX='%'
NUMBER_SUFFIX=''
MSGBOX TEXT(number)
= octal (radix 8)
NUMBER_RADIX=8
NUMBER_PREFIX=''
NUMBER_SUFFIX='o'
MSGBOX TEXT(number)
= octal (radix 8), alternate output format
NUMBER_RADIX=8
NUMBER_PREFIX='0'
NUMBER_SUFFIX=''
MSGBOX TEXT(number)
= decimal (base 10)
NUMBER_RADIX=10
NUMBER_PREFIX=''
NUMBER_SUFFIX=''
MSGBOX TEXT(number)
= decimal (base 10), "alternate" format
NUMBER_RADIX=10
NUMBER_PREFIX='(prefix) '
NUMBER_SUFFIX=' (suffix)'
MSGBOX TEXT(number)
= hexadezimal (radix 16)
NUMBER_RADIX=16
NUMBER_PREFIX='0x'
NUMBER_SUFFIX=''
MSGBOX TEXT(number)
= hexadezimal (radix 16), alternate output format
NUMBER_RADIX=16
NUMBER_PREFIX=''
NUMBER_SUFFIX='h'
MSGBOX TEXT(number)
|
|
NUMBER
TEXT2DATA(
data,
index,
count)
more...
less...
The TEXT2DATA() function is the counterpart of the DATA2TEXT()
function. It is used to extract numeric values from tables created by
DATA2TEXT().
data contains the binary data
values.
index is the index to the data TEXT string, where data extraction starts,
multiplied by the count parameter
value.
count is either the negative value of
a data type constant or the amount of data to be extracted
(deprecated). The type of the data returned by TEXT2DATA() depends on
this parameter.
Sample:
= power of 2 table example
INCLUDE 'def.mps'
OPTION GLOBALVARS, 1
VAR ptable TEXT, num SIGQWORD
= store the next power of 2 as SIGQWORD in ptable
LOCAL create_table
CONCAT ptable, DATA2TEXT(SIGQWORD(num))
INC num, num
ENDLOCAL
VAR inp TEXT q SIGQWORD power SIGQWORD
LET num = 1
LET ptable = ''
LOOP create_table 63
REPEAT
REPEAT
REPEAT
LET inp = INPUT('Enter a number between 0 and 62')
UNTIL ISNUMBER(inp)
LET q = SIGQWORD(inp)
UNTIL (q < 63) AND (q >= 0)
= power values are stored as SIGQWORD, so SIGQWORD_SIZE or -SIGQWORD_DATA must be used
= to access the correct data
power = TEXT2DATA(ptable, q, -SIGQWORD_DATA)
MSGBOX ( '2 ** '+DEC(q)+' = '+DEC(power))
UNTIL 0
|
|
NUMBER
TEXT2DATABE(
data,
index,
count)
more...
less...
The TEXT2DATABE() function is the counterpart of the
DATA2TEXTBE() function. It is used to extract numeric values from
tables created by DATA2TEXTBE().
data contains the binary data values
in BIG ENDIAN format.
index is the index to the data TEXT string, where data extraction starts,
multiplied by the count parameter
value.
count is either the negative value of
a data type constant or the amount of data to be extracted
(deprecated). The type of the data returned by TEXT2DATABE() depends on
this parameter.
Sample:
= power of 2 table example
INCLUDE 'def.mps'
OPTION GLOBALVARS, 1
VAR ptable TEXT, num SIGQWORD
= store the next power of 2 as SIGQWORD in ptable
LOCAL create_table
CONCAT ptable, DATA2TEXTBE(SIGQWORD(num))
INC num, num
ENDLOCAL
VAR inp TEXT q SIGQWORD power SIGQWORD
LET num = 1
LET ptable = ''
LOOP create_table 63
REPEAT
REPEAT
REPEAT
LET inp = INPUT('Enter a number between 0 and 62')
UNTIL ISNUMBER(inp)
LET q = SIGQWORD(inp)
UNTIL (q < 63) AND (q >= 0)
= power values are stored as SIGQWORD, so SIGQWORD_SIZE or -SIGQWORD_DATA must be used
= to access the correct data
power = TEXT2DATABE(ptable, q, -SIGQWORD_DATA)
MSGBOX ( '2 ** '+DEC(q)+' = '+DEC(power))
UNTIL 0
|
|
TEXT
TEXTCHOP(
string [,
flags])
more...
less...
TEXTCHOP() is used to remove preceding and/or trailing
whitespaces from a string (whitespaces are characters from
0x00..0x20).
string is the text expression to be
chopped.
The optional
flags parameter tells the
function where to remove whitespaces:
- "pt" (default): remove preceding and trailing
whitespaces
- "p": remove preceding whitespaces only
- "t": remove trailing whitespaces only
Sample:
VAR in TEXT, out TEXT
= generate a string with garbage at beginning and end
in = "\t STRING\n\r"
= in: (0x09)(0x20)"STRING"(0x0a)(0x0d)
out = TEXTCHOP(in) := (or out = TEXTCHOP(in,"pt"))
= out now contains "STRING"
out = TEXTCHOP(in, "p")
= out now contains "STRING"(0x0a)(0x0d)
out = TEXTCHOP(in, "t")
= out now contains (0x09)(0x20)"STRING"
TEXT
TEXTCONVERT(
string,
source,
target)
more...
less...
TEXTCONVERT() is used to convert the text
string from
character translation
source to character translation
target.
source and
target can be one of the following values (symbols
are defined in DEF.MPS):
- TEXTCONVERT_ANSI (= 1): the text string is in ANSI format (source) or is to be converted into ANSI format
(target)
- TEXTCONVERT_DOS8 (= 2): DOS character set
- TEXTCONVERT_ASCII7 (= 3): 7 Bit ASCII character set
- TEXTCONVERT_MAC (= 4): Macintosh™ character set
- TEXTCONVERT_EBCDIC (= 5): EBCDIC codepage 38 character
set
- TEXTCONVERT_UNICODE (= 6): Two Byte Unicode character set
(little endian)
- TEXTCONVERT_UNICODEBE (= 7): Two Byte Unicode character
set (big endian)
- TEXTCONVERT_CUSTOM (= 255): Custom character set
Sample:
= include the TEXTCONVERT_... symbols
INCLUDE 'DEF.MPS'
VAR sAnsi TEXT, sEbcdic TEXT, sUnicode Text
= store a text
sAnsi = 'Hello world!'
= now convert the text from ansi to ebcdic
sEbcdic = TEXTCONVERT(sAnsi, TEXTCONVERT_ANSI, TEXTCONVERT_EBCDIC)
= now the text is stored in ebcdic cp 38 in sEbcdic
= now convert the text from ebcdic to unicode
sUnicode = TEXTCONVERT(sEbcdic, TEXTCONVERT_EBCDIC, TEXTCONVERT_UNICODE)
= now the text is stored in unicode little endian in sUnicode
= now convert the text back from unicode to ansi
sAnsi = TEXTCONVERT(sUnicode, TEXTCONVERT_UNICODE, TEXTCONVERT_ANSI)
= now the text 'Hello world!' should be stored in ansi in sAnsi
= show whether it works (many special and unicode characters cannot be converted correctly, but
= normal ascii characters should work)
MSGBOX sAnsi
|
|
TEXT
TEXTCOPY(
string,
start [,
count])
more...
less...
The TEXTCOPY() function returns a part of the value of
string.
start is the index to the first
character of string to copy (the first
char is at index 1, not 0!).
count is the amount of characters to
copy. If this parameter is omitted, all characters from start up to the last character are copied.
Sample:
var txt1 TEXT, txt2 TEXT
txt1="This is a text"
txt2=TEXTCOPY(txt1, 6, 2)
= txt2 now contains the text "is"
MSGBOX txt2
TEXT
TEXTCUT(
stringref,
start [,
count])
more...
less...
The TEXTCUT() function extracts a part of the value of the TEXT
variable referenced by stringref and
returns the extracted text.
start is the index to the first
character of the TEXT variable referenced by stringref to extract (the first char is at index
1, not 0!).
count is the amount of characters to
extract. If this parameter is omitted, all characters from start up to the last character are extracted.
Sample:
var txt1 TEXT, txt2 TEXT
txt1="This is a text"
txt2=TEXTCUT(@txt1, 6, 2)
= txt2 now contains the text "is", txt1 now contains "This a text"
MSGBOX txt2
MSGBOX txt1
more...
less...
TEXTLEN() returns the length (in characters) of string.
Sample:
var inp TEXT
REPEAT
inp=INPUT('Enter a text consisting of exactly six characters')
UNTIL TEXTLEN(inp) == 6
TEXT
TEXTLINE(
lines,
index)
*
more...
less...
TEXTLINE() returns the line index of the text lines. This function is used to work with text
files (TEXT variables that contain multiple lines separated by newline
characters (chr(10) and/or chr(13)). The first line is at index 0.
Sample:
var str TEXT line TEXT
str="Line 1\nLine 2\rLine 3":= supports different newline characters
= display the third number (as the function is zero-based, use index 2!)
line=TEXTLINE(str, 2)
MSGBOX ("Third line is '"+line+"'")
more...
less...
TEXTLINECOUNT() returns the number of lines stored in the text
lines. Lines are separated by newline
characters (chr(10) and/or chr(13)).
Sample:
var str TEXT count LONGWORD
str="Line 1"+CHAR(0x0d)+CHAR(0x0a)+"Line 2"+CHAR(0x0d)+"Line 3"+CHAR(0x0a)+"Line 4":= supports 0d0a, 0d and 0a
= count the number of lines in str
count=TEXTLINECOUNT(str)
MSGBOX (DEC(count)+' lines in text')
more...
less...
TEXTLOWER() converts all characters in string to lower case and returns the converted
TEXT.
Sample:
var str TEXT
str="Lower Case"
str=TEXTLOWER(str)
= str is set to "lower case" now
MSGBOX str
more...
less...
TEXTPOS() returns the index of the first occurance of the string
substr in string. If substr
is not contained in string, 0 is
returned.
Sample:
var inp TEXT
REPEAT
inp=INPUT('Enter a string that contains the text "hex"')
UNTIL TEXTPOS("hex",inp) > 0
more...
less...
TEXTUPPER() converts all characters in string to upper case and returns the converted
TEXT.
Sample:
var str TEXT
str="Upper Case"
str=TEXTUPPER(str)
= str is set to "UPPER CASE" now
MSGBOX str
more...
less...
TRUNC() returns the ordinal value of the argument number, rounded towards 0.
Sample:
MSGBOX (DEC(TRUNC(2.0))):= results in "2"
MSGBOX (DEC(TRUNC(2.9999))):= results in "2"
MSGBOX (DEC(TRUNC(-2.9999))):= results in "-2"
more...
less...
TYPEOF() returns the data type of
expr.
An expression has one of the following data types:
- CHAR_DATA (=1): CHAR
data type
- BYTE_DATA (=2): BYTE
data type
- WORD_DATA (=3): WORD
data type
- LONGWORD_DATA (=4): LONGWORD data type
- SIGQWORD_DATA (=5): SIGQWORD data type
- TEXT_DATA (=6): TEXT
data type
- FILE_DATA (=7): FILE
data type
- VARREF_DATA (=8): VARREF data type
- SINGLE_DATA (=9): SINGLE data type
- DOUBLE_DATA (=10): DOUBLE data type
- EXTENDED_DATA (=11): EXTENDED data type
- COMP_DATA (=12): COMP
data type
- SIGBYTE_DATA (=13): SIGBYTE data type
- SIGWORD_DATA (=14): SIGWORD data type
- SIGLONGWORD_DATA (=14): SIGLONGWORD data type
Sample:
= show data type example
INCLUDE 'def.mps'
OPTION GLOBALVARS, 1
VAR output TEXT
= get a textual data type representation
LOCAL getdatatype
VAR stack VARREF
VAR type SIGBYTE
VAR types TEXT
LET types = <<
none
character
unsigned byte
unsigned word
unsigned long
signed quad
text
file
variable reference
single float
double float
extended float
comp float
signed byte
signed word
signed long
>>
POP stack
LET type = TYPEOF(DEREF(stack))
IF ((type <= SIGLONGWORD_DATA) AND (type >= 0))
RETURN TEXTLINE(types, type)
ENDIF
RETURN "unknown"
ENDLOCAL
LOCAL sub_tp
VAR msg TEXT varn TEXT
LET msg = #getdatatype
POP varn
CONCAT output, (varn+" is of type "+msg+"\n")
ENDLOCAL
VAR charV CHAR, byteV BYTE, wordV WORD, longwordV LONGWORD
VAR sigqwordV SIGQWORD, textV TEXT, fileV FILE, refV VARREF, noneV NONE
VAR singleV SINGLE, doubleV DOUBLE, extendedV EXTENDED, compV COMP
VAR sigbyteV SIGBYTE, sigwordV SIGWORD, siglongwordV SIGLONGWORD
call sub_tp, 'charV', @charV
call sub_tp, 'byteV', @byteV
call sub_tp, 'wordV', @wordV
call sub_tp, 'longwordV', @longwordV
call sub_tp, 'sigqwordV', @sigqwordV
call sub_tp, 'textV', @textV
call sub_tp, 'fileV', @fileV
call sub_tp, 'refV', @refV
call sub_tp, 'noneV', @noneV
call sub_tp, 'singleV', @singleV
call sub_tp, 'doubleV', @doubleV
call sub_tp, 'compV', @compV
call sub_tp, 'extendedV', @extendedV
call sub_tp, 'sigbyteV', @sigbyteV
call sub_tp, 'sigwordV', @sigwordV
call sub_tp, 'siglongwordV', @siglongwordV
TEXTBOX output
|
|
more...
less...
The
WORD() function is used to convert the expression
expr to the
WORD data type.
If
expr is a numeric or CHAR
expression, the lowest 16 bits of its ordinal value are returned.
If
expr is of type TEXT, Tiny Hexer
tries to convert the text string to a number. If conversion fails, an
error is raised. If conversion succeeds, the lowest 16 bits of the
converted number are returned.
Sample:
= convert a text to a word number
VAR inp TEXT w WORD
REPEAT
inp = INPUT('Enter a numeric value')
UNTIL ISNUMBER(inp)
LET w = WORD(inp)
= output hexadecimal
MSGBOX ('The number you entered was (hex): '+HEX(w))